- if @group
  - @title = t('attendance.heading_html', group: link_to(@group.name, @group), when: @attended_at.to_s(:date))
- else
  - @title = t('attendance.heading_without_group', when: @attended_at.to_s(:date))

- content_for :header do
  %section.content-header
    = breadcrumbs
    %h1
      %small
        = link_to prev_administration_attendance_index_path(attended_at: @attended_at) do
          = icon 'fa fa-arrow-circle-o-left'
      = @title
      %small
        = link_to next_administration_attendance_index_path(attended_at: @attended_at) do
          = icon 'fa fa-arrow-circle-o-right'

.row
  .col-md-9
    %p#record-count
      = t('attendance.records', count: @record_count)

    - if @records.any?
      = pagination @records

      %table.table.print-full-width
        %thead
          %tr
            %th= sortable_column_heading t('attendance.name'),          'attendance_records.last_name,attendance_records.first_name', %w(attended_at group_id)
            %th= sortable_column_heading t('attendance.adult'),         'people.child',                                               %w(attended_at group_id)
            %th= sortable_column_heading t('attendance.group'),         'groups.name',                                                %w(attended_at group_id)
            %th= sortable_column_heading t('attendance.class_time'),    'attendance_records.attended_at',                             %w(attended_at group_id)
            %th= sortable_column_heading t('attendance.recorded_time'), 'attendance_records.created_at',                              %w(attended_at group_id)
            %th= t('attendance.can_pickup_people')
            %th= t('attendance.cannot_pickup_people')
            %th.actions
        %tbody
          - @records.each do |record|
            %tr{:id => "record#{record.id}"}
              %td
                - if record.first_name.present?
                  - if record.person
                    = link_to "#{record.first_name} #{record.last_name}", record.person
                  - else
                    = record.first_name
                    = record.last_name
                - elsif record.person
                  = link_to record.person.name, record.person
                - else
                  %em= t('attendance.name_unknown')
              %td
                - if record.person && record.person.adult?
                  = t('attendance.adult')
              %td
                - if record.group
                  = link_to record.group.name, record.group
                - else
                  %em= t('attendance.group_missing')
              %td
                = record.attended_at.to_s(:time)
              %td
                = record.created_at.to_s(:time)
              %td
                = record.all_pickup_people.join(', ')
              %td
                = record.cannot_pick_up
              %td.actions
                = link_to administration_attendance_path(record), data: { remote: true, method: 'delete', confirm: t('are_you_sure') }, class: 'btn btn-delete btn-xs' do
                  = icon 'fa fa-trash-o'
            - if record.medical_notes.present?
              %tr.details
                %td{ colspan: 7 }
                  = t('attendance.medical_notes')
                  = record.medical_notes

      = pagination @records

    - else
      %p
        %em= t('attendance.no_records')

  .col-md-3
    .box.box-info.hidden-print
      .box-heading
      .box-body
        = form_tag administration_attendance_index_path, method: :get do
          .form-group
            = label_tag :attended_at, t('attendance.date')
            = date_field_tag :attended_at, @attended_at.to_s(:date), class: 'form-control', onchange: 'this.form.submit()'
          .form-group
            = label_tag :person_name, t('attendance.search_person')
            .input-group
              = text_field_tag :person_name, params[:person_name], class: 'form-control'
              %span.input-group-btn
                - if params[:person_name]
                  = link_to administration_attendance_index_path(attended_at: @attended_at, group_id: params[:group_id]), class: 'btn btn-danger' do
                    = icon 'fa fa-times-circle'
                = button_tag class: 'btn btn-info' do
                  = icon 'fa fa-search'

        - if @groups.any?
          = form_tag groups_path, method: 'get', data: { remote: true }, id: 'group-search' do
            = hidden_field_tag :select_group, true
            = hidden_field_tag :include_hidden, true
            .form-group
              = label_tag :name, t('admin.attendance.add_group.search.heading')
              .input-group
                = text_field_tag :name, '', class: 'form-control'
                %span.input-group-btn
                  = button_tag icon('fa fa-search'), class: 'btn btn-info'
          #add_group{ style: "display:none" }
            = form_tag administration_attendance_index_path, method: 'get' do
              - Array(params[:ids]).each do |group_id|
                = hidden_field_tag 'ids[]', group_id
              = hidden_field_tag 'person_name', params[:person_name] if params[:person_name].present?
              = hidden_field_tag 'attended_at', params[:attended_at] if params[:attended_at].present?
              #group_results
              .form-group.push-down
                = button_tag t('admin.attendance.add_group.button'), class: 'btn btn-success'
          #no_group_results{ style: "display:none" }
            = t('none')
          - if params[:ids]
            = form_tag administration_attendance_index_path, method: 'get' do
              = hidden_field_tag 'person_name', params[:person_name] if params[:person_name].present?
              = hidden_field_tag 'attended_at', params[:attended_at] if params[:attended_at].present?
              - @groups.each do |group|
                = check_box_tag 'ids[]', group.id, "group_#{group.id}"
                = label_tag "group_#{group.id}", group.name
                %br
              = button_tag t('admin.attendance.groups_list.update.button'), class: 'btn btn-success'

        - if @records.any?
          %p.push-down
            = link_to administration_attendance_index_path(format: 'csv', attended_at: @attended_at, group_id: params[:group_id], person_name: params[:person_name]), class: 'btn btn-primary' do
              = icon 'fa fa-download'
              = t('attendance.export')
